package com.blog.backend.controller;

import com.blog.backend.domain.BlogInfo;
import com.blog.backend.domain.DTO.BlogDTO;
import com.blog.backend.domain.DTO.UserDTO;
import com.blog.backend.service.BlogService;
import com.blog.common.annotation.Anonymous;
import com.blog.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Auman
 * @time 2024/4/28 10:08
 */

@Api(tags = "知码意相关controller")
@RequestMapping("/blog")
@RestController
public class BlogController {

    @Autowired
    private BlogService service;

    @Anonymous
    @ApiOperation("查看blog")
    @PostMapping("/getBlog")
    public R<List<BlogInfo>> getBlog(@Validated @RequestBody UserDTO dto) {
        return R.ok(service.getBlog(dto));
    }

    @Anonymous
    @ApiOperation("新增blog")
    @PostMapping("/newBlog")
    public R newBlog(@Validated @RequestBody BlogDTO dto) {
        return service.newBlog(dto)>0? R.ok():R.fail();
    }

    @Anonymous
    @ApiOperation("修改 、 删除blog")
    @PostMapping("/updateDelBlog")
    public R updateDelBlog(@Validated @RequestBody BlogDTO dto) {
        return service.updateDelBlog(dto);
    }

}
